package edu.friday.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import edu.friday.common.result.Pageable;
import edu.friday.common.result.TableDataInfo;
import edu.friday.mapper.SysRoleMapper;
import edu.friday.model.SysRole;
import edu.friday.model.SysUser;
import edu.friday.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    SysRoleMapper sysRoleMapper;

    @Override
    public TableDataInfo selectRoleList(SysRole role, Pageable page) {
        Page<SysUser> pages = PageHelper.startPage(page.getPage(),page.getSize());
        List<SysRole> sysRoles =sysRoleMapper.selectAll(role);
        TableDataInfo t=TableDataInfo.success(sysRoles,pages.getTotal());
        return t;
    }

    @Override
    public int insertRole(SysRole role) {
        return sysRoleMapper.insertSelective(role);
    }

    @Override
    public int deleteRoleByIds(Long[] roleIds) {
        return sysRoleMapper.deleteByIds(roleIds);
    }

    @Override
    public int updateRole(SysRole role) {
        return sysRoleMapper.updateByPrimaryKeySelective(role);
    }

    @Override
    public List<SysRole> selectRoleAll() {
        return sysRoleMapper.selectAll(new SysRole());
    }

    @Override
    public SysRole selectRoleById(Long roleId) {
        return sysRoleMapper.selectByPrimaryKey(roleId);
    }

    @Override
    public Set<String> selectRolePermissionByUserId(Long userId) {
        //TODO
        return null;
    }

    @Override
    public List<Long> selectRoleListByUserId(Long userId) {
        return sysRoleMapper.selectRoleIdsByUserId(userId);
    }
}
